package org.jmhome.blog.service.impl;

import java.util.List;

import org.jmhome.blog.model.User;
import org.jmhome.blog.service.AbstractJpaDaoService;
import org.jmhome.blog.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service("userService")
public class UserServiceImpl extends AbstractJpaDaoService implements UserService {

	@Override
	public void insertUser(User user) {
		getJpaTemplate().persist(user);

	}

	@Override
	public void updateUser(User user) {
		getJpaTemplate().merge(user);

	}

	@Override
	public void deleteUser(User user) {
		getJpaTemplate().remove(user);
	}

	@Override
	public User getUser(String email) {
		return getJpaTemplate().find(User.class, email);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<User> getUsers(int startNum, int listCount) {
		List<User> users = getJpaTemplate().findByNamedQuery("org.jmhome.blog.model.User@Users");
		return users;
	}

	@SuppressWarnings("unchecked")
	@Override
	public int getUserAllCount() {
		List<User> users = getJpaTemplate().findByNamedQuery("org.jmhome.blog.model.User@Users");
		return users.size();
	}

}
